﻿using System;
using Galaxy.Core;
using Galaxy.ModuleInspector;
using Galaxy.ModuleInterface.Messages;
using Galaxy.TestModule;

namespace ConsoleTest
{
    static class Program
    {
        static private GalaxyCore Core = new GalaxyCore();
        static private MessageSenderModule sf_MessageSenderModule = new MessageSenderModule();
        static private TextWriterModule TextWriterModule =
            new TextWriterModule(Console.Out, "qwe");
        static private GalaxyModuleInspector ModuleInspector = new GalaxyModuleInspector();


        [STAThread]
        static void Main(string[] args)
        {
            CoreTest();
            //TestClass Test = new TestClass("123");

            //BinaryFormatter Serializer = new BinaryFormatter();

            //MemoryStream Stream = new MemoryStream();

            //Serializer.Serialize(Stream, Test);

            //Stream.Position = 0;

            //Test = Serializer.Deserialize(Stream) as TestClass;

            Console.WriteLine("Работу закончил.");

            Console.ReadLine();
        }

        private static void CoreTest()
        {
            //ModulList MList = new ModulList();
            //MList.Add(new Module("Модуль.dll",
            //    new Class("MessageSenderModule", 1, 1f, 1d, "qwe"),
            //    new Class("TextWriterModule")));
            //MList.Add(new Module("Ядро.dll",
            //    new Class("GalaxyCore", "qwe", 1)));
            //MList.Add(new Module("Портал.dll",
            //    new Class("CTCPPortal", 4567),
            //    new Class("CUDPPortal", "255.255.255.255", 4568)));

            //Serialize(MList);

            Core.AddModule(sf_MessageSenderModule);
            Core.AddModule(TextWriterModule);
            Core.AddModule(ModuleInspector);

            Core.Start();

            Console.WriteLine();
            Console.WriteLine("Работа Галактики");
            Console.WriteLine();

            Console.WriteLine("Отправка сообщений");
            sf_MessageSenderModule.SendMessage("Test");
            sf_MessageSenderModule.SendInvokeMessage();
            sf_MessageSenderModule.SendMessage("Test 1", TextWriterModule);
            sf_MessageSenderModule.SendInvokeMessage(TextWriterModule);
            sf_MessageSenderModule.SendMessage(new StopModuleMessage(sf_MessageSenderModule),
                sf_MessageSenderModule);
            sf_MessageSenderModule.SendMessage(new StartModuleMessage(sf_MessageSenderModule),
                sf_MessageSenderModule);
            sf_MessageSenderModule.SendMessage(new InitializeModuleMessage(sf_MessageSenderModule),
                sf_MessageSenderModule);

            Console.ReadLine();
            Console.WriteLine("Остановка Галактики");
            Console.WriteLine();

            ModuleInspector.Stop();
            Core.Stop();
        }
    }
}
